package com.jialin.test.spring;

import java.util.List;
import java.util.Map;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;







public class Main {
	public static void main(String[] args) {
		//spring.xml 位于 test/spring.xml
		//classPath指的的是\base\src\main\test
		//ApplicationContext web=new ClassPathXmlApplicationContext("spring.xml");
		
		ApplicationContext web = new FileSystemXmlApplicationContext(   
		"src/main/test/com/jialin/test/spring/spring.xml");   
		
		Start s= (Start)web.getBean("start");
		s.run();
		
		//test simpleJdbcTemplate
		SimpleJdbcTemplate jdbc=(SimpleJdbcTemplate) web.getBean("simpleJdbcTemplate");
		String sql1="select * from person";
		//List<Map<String, Object>> list= jdbc.queryForList(sql1);
		
		
		//这个方法即使数据库字段多几个，也不会出错
		List<Person> pp=jdbc.query(sql1,new BeanPropertyRowMapper(Person.class));
		
		for(Person p:pp)
		{
			System.out.println(p);
		}
	
		
		
	}
}
